
//引入路由组件
import Home from '@/Pages/Home';//首页
import Login from '@/Pages/Login';//登录
import Register from '@/Pages/Register';//注册
import Search from '@/Pages/Search';//搜索
import Detail from '@/Pages/Detail';//详情
import AddCartSuccess from '@/Pages/AddCartSuccess';
import ShopCart from '@/Pages/ShopCart';//购物车
import Trade from '@/Pages/Trade';//核对地址信息
import Pay from '@/Pages/Pay';//支付
import PaySuccess from '@/Pages/PaySuccess';//支付完成
import Center from '@/Pages/Center';//查看已购买的订单
//二级路由组件
import MyOrder from '@/Pages/Center/myOrder'
import GroupOrder from '@/Pages/Center/groupOrder'

//路由配置信息
export default [
  //查看付款成功的商品
  {
    path: '/center',
    component: Center,
    meta: { show: true },
    //二级路由组件
    children: [
      {
        path: 'myorder',
        component: MyOrder
      },
      {
        path: 'grouporder',
        component: GroupOrder
      },
      //重定向 
      {
        path: '/center',
        redirect: '/center/myorder'
      }
    ]
  },
  {
    path: '*',
    redirect: "/home"
  },
  {
    path: "/home",
    component: Home,
    meta: { show: true }
  },
  {
    path: "/search/:keyword?",
    component: Search,
    meta: { show: true },
    name: 'search'
  },
  {
    path: "/login",
    component: Login,
    meta: { show: false }
  },
  {
    path: "/register",
    component: Register,
    meta: { show: false }
  },
  //
  {
    path: "/detail/:skuid",
    component: Detail,
    meta: { isShow: true }
  },
  {
    path: "/addcartsuccess",
    name: 'addcartsuccess',//路由命名
    component: AddCartSuccess,
    meta: { show: true }
  },
  //结算购物车
  {
    path: "/shopcart",
    component: ShopCart,
    meta: { show: true }
  },
  //结算订单
  {
    path: "/trade",
    component: Trade,
    meta: { show: true },
    //路由独享守卫
    beforeEnter: (to, from, next) => {
     //去交易页面，必须是从购物车页面去的
     if(from.path == "/shopcart"){
      next();
     }else{
      //从其他的路由组件是不能进去的，只能停留在当前
      next(false);
     }
    },
  },
  //付款交易
  {
    path: "/pay",
    component: Pay,
    meta: { show: true },
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      if(from.path =="/trade"){
        next();
      }else{
        next(false);
      }
    }
  },
  //付款成功
  {
    path: '/paysuccess',
    component: PaySuccess,
    meta: { show: true }
  },

]